﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Collections.Generic;
using DangKyHocPhan;

namespace EntityServices
{
    /// <summary>
    /// Summary description for LopHoc
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class LopHoc : System.Web.Services.WebService
    {

        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }

        [WebMethod(Description = " lay danh sach lop hoc cho Sinh vien")]
        public  DangKyHocPhan.PhanHoiDanhSachLopHocDuocMo layDanhSachLopHocDuocMoChoSinhVien(DangKyHocPhan.YeuCauDanhSachLopHocDuocMoChoSinhVien yeucau)
        {
            return DangKyHocPhan.LopHocService.layDanhSachLopHocDuocMoChoSinhVien(yeucau);
        }

        [WebMethod(Description = "Them Sinh vien vao lop")]
        public bool themSinhVienVaoLop(DangKyHocPhan.YeuCauThemSinhVienVaoLop yeucau)
        {
            return DangKyHocPhan.LopHocService.themSinhVienVaoLop(yeucau);
        }

        [WebMethod(Description = " lay danh sach lop hoc da dang ky cua Sinh vien")]
        public DangKyHocPhan.PhanHoiDanhSachLopHocDaDangKy layDanhSachLopHocDaDangKy(DangKyHocPhan.YeuCauLopHocDaDangKy yeucau)
        {
            return DangKyHocPhan.LopHocService.layDanhSachLopHocDaDangKy(yeucau);
        }
        [WebMethod(Description = " xoa Sinh vien khoi Lop")]
        public void xoaSinhVienKhoiLop(DangKyHocPhan.YeuCauXoaSinhVienKhoiLop yeucau)
        {
            DangKyHocPhan.LopHocService.xoaSinhVienKhoiLop(yeucau);
        }
        [WebMethod]
        public bool LuuDiemThiGiuaKy(string MaSoSinhVien, string MaLopHoc, float DiemGiuaKy, float DiemQuaTrinh, float DiemCuoiKy)
        {
            try
            {
                HTQLGiaoDucDataContext db = new HTQLGiaoDucDataContext();
                int sinhVienID = 0;
                foreach (SINH_VIEN sv in db.SINH_VIENs)
                {
                    if (sv.MASOSINHVIEN == MaSoSinhVien)
                    {
                        sinhVienID = sv.SINHVIENID;
                    }
                }

                int lopHocID = 0;
                foreach (LOP_HOC lh in db.LOP_HOCs)
                {
                    if (lh.MALOPHOC == MaLopHoc)
                    {
                        lopHocID = lh.LOPHOCID;
                    }
                }

                SV_HOC_LOP svhl = new SV_HOC_LOP { LOPHOCID = lopHocID, SINHVIENID = sinhVienID, DIEMGIUAKY = DiemGiuaKy, DIEMQUATRINH = DiemQuaTrinh, DIEMCUOIKY = DiemCuoiKy };
                
                db.SV_HOC_LOPs.InsertOnSubmit(svhl);
                db.SubmitChanges();
            }
            catch
            {
                return false;
            }
            return true;
        }

        [WebMethod]
        public bool CapNhatDiemGiuaKy(string MaSoSinhVien, string MaLopHoc, float DiemGiuaKyCN)
        {
            bool kq = true;

            try
            {
                HTQLGiaoDucDataContext db = new HTQLGiaoDucDataContext();
                int sinhVienID = 0;
                foreach (SINH_VIEN sv in db.SINH_VIENs)
                {
                    if (sv.MASOSINHVIEN == MaSoSinhVien)
                    {
                        sinhVienID = sv.SINHVIENID;
                    }
                }

                int lopHocID = 0;
                foreach (LOP_HOC lh in db.LOP_HOCs)
                {
                    if (lh.MALOPHOC == MaLopHoc)
                    {
                        lopHocID = lh.LOPHOCID;
                    }
                }
                foreach (SV_HOC_LOP svhl in db.SV_HOC_LOPs)
                {
                    if (svhl.LOPHOCID == lopHocID && svhl.SINHVIENID == sinhVienID)
                    {
                        svhl.DIEMGIUAKY = DiemGiuaKyCN;
                        db.SubmitChanges();
                    }
                }
            }
            catch
            {
                kq = false;
            }
            return kq;
        }

        [WebMethod]
        public bool CapNhatDiemQuaTrinh(string MaSoSinhVien, string MaLopHoc, float DiemQuaTrinhCN)
        {
            bool kq = true;

            try
            {
                HTQLGiaoDucDataContext db = new HTQLGiaoDucDataContext();
                int sinhVienID = 0;
                foreach (SINH_VIEN sv in db.SINH_VIENs)
                {
                    if (sv.MASOSINHVIEN == MaSoSinhVien)
                    {
                        sinhVienID = sv.SINHVIENID;
                    }
                }

                int lopHocID = 0;
                foreach (LOP_HOC lh in db.LOP_HOCs)
                {
                    if (lh.MALOPHOC == MaLopHoc)
                    {
                        lopHocID = lh.LOPHOCID;
                    }
                }

                foreach (SV_HOC_LOP svhl in db.SV_HOC_LOPs)
                {
                    if (svhl.LOPHOCID == lopHocID && svhl.SINHVIENID == sinhVienID)
                    {
                        svhl.DIEMQUATRINH = DiemQuaTrinhCN;
                        db.SubmitChanges();
                    }
                }
            }
            catch
            {
                kq = false;
            }
            return kq;
        }

        [WebMethod]
        public bool CapNhatDiemCuoiKy(string MaSoSinhVien, string MaLopHoc, float DiemCuoiKyCN)
        {
            bool kq = true;

            try
            {
                HTQLGiaoDucDataContext db = new HTQLGiaoDucDataContext();
                int sinhVienID = 0;
                foreach (SINH_VIEN sv in db.SINH_VIENs)
                {
                    if (sv.MASOSINHVIEN == MaSoSinhVien)
                    {
                        sinhVienID = sv.SINHVIENID;
                    }
                }

                int lopHocID = 0;
                foreach (LOP_HOC lh in db.LOP_HOCs)
                {
                    if (lh.MALOPHOC == MaLopHoc)
                    {
                        lopHocID = lh.LOPHOCID;
                    }
                }

                foreach (SV_HOC_LOP svhl in db.SV_HOC_LOPs)
                {
                    if (svhl.LOPHOCID == lopHocID && svhl.SINHVIENID == sinhVienID)
                    {
                        svhl.DIEMCUOIKY = DiemCuoiKyCN;
                        db.SubmitChanges();
                    }
                }
            }
            catch
            {
                kq = false;
            }
            return kq;
        }
    }
}
